using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Text;

namespace WebApplication
{
  public class SpecificTypeConverter : TypeConverter
  {
    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    {
      if (sourceType == typeof(String))
        return true;
      return base.CanConvertFrom(context, sourceType);
    }

    public override object ConvertFrom(ITypeDescriptorContext context,
      CultureInfo culture, object value)
    {
      if (value is String)
      {
        string[] values;

        values = ((string)value).Split('_');
        return new System.Drawing.Point(int.Parse(values[0]), int.Parse(values[1]));
      }
      return base.ConvertFrom(context, culture, value);
    }

    public override object ConvertTo(ITypeDescriptorContext context,
       CultureInfo culture, object value, Type destinationType)
    {
      if (destinationType == typeof(String))
      {
        return ((System.Drawing.Point)value).X + "_" + ((System.Drawing.Point)value).Y;
      }
      return base.ConvertTo(context, culture, value, destinationType);
    }
  }
}
